import request from '@/utils/request'
import qs from 'qs'

export function findListByPage(params) {
  return request({
    url: '/api/script/analyze/task' + '?' + qs.stringify(params, { indices: false }),
    method: 'get'
  })
}

export function queryById(pkId) {
  return request({
    url: '/api/script/analyze/task/' + pkId,
    method: 'get'
  })
}

export function filesUpload(data) {
  return request({
    url: '/api/script/analyze/list/improt',
    method: 'post',
    data
  })
}

export function scriptAnalyze(pkId) {
  return request({
    url: '/api/script/analyze/task/analyze/' + pkId,
    method: 'put'
  })
}

export function del(pkIds) {
  return request({
    url: '/api/script/analyze/task',
    method: 'delete',
    data: pkIds
  })
}

export function add(data) {
  return request({
    url: '/api/script/analyze/task',
    data: data,
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data;boundary=' + new Date().getTime()
    }
  })
}

export function upload(data) {
  return request({
    url: '/api/script/analyze/task/upload',
    data: data,
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data;boundary=' + new Date().getTime()
    }
  })
}

export function downloadFile(taskPkId) {
  return request({
    url: '/api/script/analyze/task/download/sourcefile/' + taskPkId,
    method: 'get',
    responseType: 'blob'
  })
}

export function checkTaskNameExists(taskName) {
  return request({
    url: '/api/script/analyze/task/checkTaskName',
    method: 'post',
    data: taskName
  })
}

export function createTransferTask(data) {
  return request({
    url: '/api/script/analyze/task/createTransferTask',
    data: data,
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data;boundary=' + new Date().getTime()
    }
  })
}

export function getMigrationTypeInfos() {
  return request({
    url: '/api/script/analyze/task/getMigrationTypeInfos',
    method: 'get'
  })
}

export default {
  queryById,
  findListByPage,
  add,
  del,
  scriptAnalyze,
  getMigrationTypeInfos,
  downloadFile,
  filesUpload,
  checkTaskNameExists,
  createTransferTask,
  upload
}
